package gwtappcontainer.server.apps.security;

import gwtappcontainer.shared.apps.security.RoleProp;
import gwtappcontainer.shared.apps.security.UserProp;

import java.util.HashSet;
import java.util.TreeSet;

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Cache;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Load;

@Entity @Cache
class UserEntity {
	@Id String email;
	
	@Load HashSet<Ref<RoleEntity>> roles = new HashSet<Ref<RoleEntity>>();
	TreeSet<String> privileges = new TreeSet<String>();
	
	UserProp toProp() {
		UserProp prop = new UserProp();
		prop.email = email;
		
		prop.roles = new TreeSet<RoleProp>();	
		for (Ref<RoleEntity> entity : roles) 
			prop.roles.add(entity.get().toProp());
		
		prop.privileges = privileges;
		
		return prop;
	}
}
